<template>
  <div class="app-container">
    <div v-if="opt != 'add' && opt != 'addContract'">
      <el-descriptions title="">
        <el-descriptions-item label="序号">
          <el-tag size="medium">{{ obj != null ? obj.index : index }}</el-tag>
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <el-tabs v-model="activeName" @tab-click="handleClick" class="contract-tabs">
      <el-tab-pane label="基本信息" name="first">
        <div    :class="grandsonClass!==null && grandsonClass=='business'? 'tab-content-business' : 'tab-content-scrollable'  ">
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-row v-if="showRelated">
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="关联合同"
                  prop="relatedContractName"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.relatedContractName"
                    disabled="disabled"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="合同名称"
                  prop="contractName"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.contractName"
                    placeholder="请输入合同名称"
                    :disabled="isView"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="合同编号"
                  prop="contractNumber"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.contractNumber"
                    placeholder="请输入合同编号"
                    :disabled="isView"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="合同金额"
                  prop="contractAmount"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.contractAmount"
                    placeholder="请输入合同金额"
                    :disabled="isView"
                    maxlength="8"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="签订时间"
                  prop="signingTime"
                  label-width="110px"
                >
                  <el-date-picker
                    clearable
                    v-model="form.signingTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择签订时间"
                    style="width: 297px"
                    :disabled="isView"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item label="结束时间" prop="endTime" label-width="110px">
                  <el-date-picker
                    clearable
                    v-model="form.endTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择结束时间"
                    style="width: 297px"
                    :disabled="isView"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="销售人员"
                  prop="salespersonName"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.salespersonName"
                    placeholder="请输入销售人员名称"
                    @focus="userShow(1)"
                    :disabled="isView"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="提供人" prop="provider" label-width="110px">
                  <el-input
                    v-model="form.provider"
                    placeholder="请输入提供人"
                    :disabled="isView"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  label="提供来源"
                  prop="provideSources"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.provideSources"
                    placeholder="请输入提供来源"
                    :disabled="isView"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="业务费" prop="cost" label-width="110px">
                  <el-input
                    v-model="form.cost"
                    placeholder="请输入业务费"
                    :disabled="isView"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item
                  label="已收金额"
                  prop="amountReceived"
                  label-width="110px"
                >
                  <el-input v-model="form.amountReceived" disabled="disabled" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row style="margin: 0px -120px 12px 40px">
              <el-row :gutter="10" class="mb8" v-if="isDel">
                <el-col :span="1.5">
                  <span
                    style="font-size: 14px; margin-left: 550px; margin-right: 5px"
                    >收款方式</span
                  >&nbsp;&nbsp;&nbsp;&nbsp;
                  <el-button
                    type="primary"
                    plain
                    icon="el-icon-plus"
                    size="mini"
                    @click="addContractInfo"
                    style="text-align: center"
                    v-if="isSave"
                  ></el-button>
                </el-col>
              </el-row>
              <el-table :data="tableData" style="width: 91%">
                <el-table-column
                  label="序号"
                  type="index"
                  align="center"
                  prop="indexTwo"
                />
                <el-table-column
                  prop="paymentName"
                  label="款项名称"
                  min-width="100"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.paymentName"
                      :disabled="isView"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="amountCollected"
                  label="应收金额"
                  min-width="60"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.amountCollected"
                      :disabled="isView"
                      maxlength="8"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="estimatedCollectionTime"
                  label="预计收款时间"
                  min-width="60"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-date-picker
                      clearable
                      v-model="scope.row.estimatedCollectionTime"
                      type="date"
                      value-format="yyyy-MM-dd"
                      :picker-options="{ disabledDate: dateOptions }"
                      placeholder="请选择预计收款时间"
                      :disabled="isView"
                    >
                    </el-date-picker>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="remark"
                  label="备注"
                  min-width="60"
                  align="center"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.remark"
                      :disabled="isView"
                      maxlength="30"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  prop="amountReceived"
                  label="已收金额"
                  min-width="40"
                  align="center"
                />
                <el-table-column
                  prop="unpaidAmount"
                  label="未收金额"
                  min-width="40"
                  align="center"
                />
                <el-table-column
                  fixed="right"
                  label="操作"
                  min-width="40"
                  align="center"
                  v-if="isSave"
                >
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      size="small"
                      icon="el-icon-delete"
                      @click="delContractListInfo(scope.row)"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </el-row>
            <el-row style="margin: 0px -120px 18px 40px">
              <div style="text-align: center">
                <el-row :gutter="10" class="mb8">
                  <el-col :span="1.5">
                    <span
                      style="font-size: 14px; margin-left: 550px; margin-right: 5px"
                    >选择1产品</span
                    >&nbsp;&nbsp;&nbsp;&nbsp;
                    <el-button
                      type="primary"
                      plain
                      icon="el-icon-plus"
                      size="mini"
                      @click="selectProduct"
                      style="text-align: center"
                      v-if="isSave"
                    ></el-button>
                  </el-col>
                </el-row>
                <el-row>产品列表</el-row>
                <el-table v-loading="loading" :data="productInfoList" style="width: 91%">
                  <el-table-column label="产品类型" align="center" prop="productCategory">
                    <template slot-scope="scope">
                      <dict-tag :options="dict.type.product_type" :value="scope.row.productCategory" />
                    </template>
                  </el-table-column>
                  <el-table-column label="产品编号" align="center" prop="productNumber" />
                  <el-table-column label="产品名称" align="center" prop="productName" />
                  <el-table-column label="产品规格" align="center" prop="productSpecs" />
                  <el-table-column label="费用" align="center" prop="pricingRange">
                    <template slot-scope="scope">
                      <el-button v-if="isBtn" @click.stop="addFees(scope.row)" size="small" type="text">{{ scope.row.pricingRange }}</el-button>
                      <el-button v-else size="small" type="text">{{ scope.row.pricingRange }}</el-button>
                    </template>
                  </el-table-column>
                  <el-table-column label="数量" align="center" prop="quantity" width="100">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.quantity"  
                      placeholder="请输入数量"
                      :disabled="isView"
                      maxlength="10"
                      @blur="handleQuantityBlur(scope.row)"  
                      @keyup.enter.native="handleQuantityBlur(scope.row)"
                    />
                  </template>
                </el-table-column>
                  <el-table-column label="合同交期" align="center" prop="contractDueDate"  >
                    <template slot-scope="scope">
                      <el-date-picker
                        clearable
                        v-model="scope.row.contractDueDate"  
                        type="date"                         
                        value-format="yyyy-MM-dd"           
                        placeholder="请选择"
                        width="115"           
                        :disabled="isView"                  
                        :picker-options="{
                          disabledDate: (time) => time.getTime() < Date.now() - 8.64e7
                        }"
                        @change="handleContractDueDateBlur(scope.row)"
                      />
                    </template>
                  </el-table-column>
                  <el-table-column label="备注" align="center" prop="remark">
                    <template slot-scope="scope">
                     <div >
                      <el-input v-model="scope.row.remark" @change="handleRemarkBlur(scope.row)"  style="width: 100%" />
                      </div>
                    </template>
                  </el-table-column>
                  <!-- <el-table-column label="下单日期" align="center" prop="orderDate" width="100" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                      <span>{{ parseTime(scope.row.OrderDate, '{y}-{m}-{d}') }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="结案日期" align="center" prop="closeDate" width="100" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                      <span>{{ parseTime(scope.row.closeDate, '{y}-{m}-{d}') }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="交付日期" align="center" prop="deliveryDate" width="100" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                      <span>{{ parseTime(scope.row.deliveryDate, '{y}-{m}-{d}') }}</span>
                    </template>
                  </el-table-column> -->
                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width" v-if="isSave" width="80">
                    <template slot-scope="scope">
                      <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteProduct(scope.row)">删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-row>
            <el-row>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="客户名称"
                  prop="enterpriseName"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.enterpriseName"
                    placeholder="请输入客户名称"
                    :readonly="readonly"
                    @focus="enterprise"
                    :disabled="isView"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="客户地址"
                  prop="customerAddress"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.customerAddress"
                    placeholder="请输入客户地址"
                    disabled="disabled"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="客户联系人"
                  prop="customerContact"
                  label-width="110px"
                >
                  <el-select
                    v-model="form.customerContact"
                    placeholder="请选择客户联系人"
                    style="width: 296px"
                    :disabled="isView"
                  >
                    <el-option
                      v-for="person in personName"
                      :value="person.name"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="联系电话"
                  prop="telephone"
                  label-width="110px"
                >
                  <el-select
                    v-model="form.telephone"
                    placeholder="请选择联系电话"
                    style="width: 296px"
                    :disabled="isView"
                  >
                    <el-option
                      v-for="phone in personPhone"
                      :value="phone.phone"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="创建人"
                  prop="creationName"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.creationName"
                    placeholder="请输入创建人"
                    disabled="disabled"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="8" style="height: 55px">
                <el-form-item
                  label="创建时间"
                  prop="creationTime"
                  label-width="110px"
                >
                  <el-date-picker
                    clearable
                    v-model="form.creationTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择创建时间"
                    style="width: 297px"
                    disabled="disabled"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24" style="height: 75px">
                <el-form-item
                  label="附加条款"
                  prop="additionalTerms"
                  label-width="110px"
                >
                  <el-input
                    v-model="form.additionalTerms"
                    type="textarea"
                    placeholder="请输入附加条款内容"
                    :autosize="{ minRows: 2, maxRows: 4 }"
                    :disabled="isView"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="16" style="height: 55px">
                <el-form-item label="附件" label-width="110px">
                  <file-view
                    :type="fileType"
                    :businessId="businessId"
                    :businessCode="contractCode"
                  ></file-view>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div style="text-align: center; margin-top: 50px">
            <el-button type="primary" @click="submitForm" v-if="isSave"
              >保 存</el-button
            >
            <el-button @click="cancel">关 闭</el-button>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="评审信息" name="third" :disabled="isReview">
        <div style="text-align: center">
          <div>
            <el-form
              ref="formReview"
              :model="formReview"
              :inline="true"
              :rules="reviewRules"
            >
              <el-row v-if="isSave" style="line-height: 1px">
                <el-col :span="7" style="margin-left: 345px">
                  <el-form-item
                    label="评审人"
                    prop="reviewer"
                    label-width="110px"
                  >
                    <el-input
                      v-model="formReview.reviewer"
                      placeholder="请选择评审人"
                      readonly="readonly"
                      style="width: 207px"
                    />
                  </el-form-item>
                  <el-input v-model="formReview.reviewerId" type="hidden" />
                </el-col>
                <el-col :span="1">
                  <el-button
                    style="margin-left: -20px"
                    type="primary"
                    @click="selectReviewUser"
                    >选择</el-button
                  >
                </el-col>
              </el-row>
            </el-form>
            <el-row>
              <el-table v-loading="loading" :data="reviewList">
                <el-table-column
                  label="评审人"
                  align="center"
                  prop="reviewer"
                  width="180"
                />
                <el-table-column
                  label="评审结果"
                  align="center"
                  prop="reviewResult"
                  width="180"
                >
                  <template slot-scope="scope">
                    <dict-tag
                      :options="dict.type.contract_review_result"
                      :value="scope.row.reviewResult"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="评审意见"
                  align="center"
                  prop="reviewComments"
                />
                <el-table-column
                  label="评审时间"
                  align="center"
                  prop="reviewTime"
                  width="180"
                >
                  <template slot-scope="scope">
                    <span>{{
                      parseTime(scope.row.reviewTime, "{y}-{m}-{d}")
                    }}</span>
                  </template>
                </el-table-column>
              </el-table>
            </el-row>
            <div style="text-align: center; margin-top: 15px">
              <el-button type="primary" @click="submitReviewForm" v-if="isSave"
                >保 存</el-button
              >
              <el-button @click="cancel">关 闭</el-button>
            </div>
          </div>
          <div></div>
        </div>
      </el-tab-pane>
    </el-tabs>
    <select-user
      ref="select"
      :type="userType"
      :sign="sign"
      @ok="selectUser"
    ></select-user>
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <el-row>
        <el-tabs
          v-model="activeNewName"
          type="card"
        >
          <el-tab-pane label="客户" name="one">
            <el-col :span="24">
              <el-form
                :model="queryEnterpriseParams"
                ref="queryFormEnterprise"
                size="small"
                :inline="true"
                v-show="showSearch"
                label-width="100px"
              >
                <el-form-item label="企业名称" prop="enterpriseName">
                  <el-input
                    v-model="queryEnterpriseParams.enterpriseName"
                    placeholder="请输入企业名称"
                    clearable
                    @keyup.enter.native="handleQueryEnterprise"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="mini"
                    @click="handleQueryEnterprise"
                    >搜索</el-button
                  >
                  <el-button
                    icon="el-icon-refresh"
                    size="mini"
                    @click="resetQueryEnterprise"
                    >重置</el-button
                  >
                  <el-button
                    type="primary"
                    size="mini"
                    @click="saveSelectEnterprise"
                    >确定</el-button
                  >
                </el-form-item>
              </el-form>
              <el-table
                ref="tableEnterprise"
                v-loading="loading"
                style="width: 100%"
                @selection-change="handleSelectionChangeEnterprise"
                :data="infoList"
                highlight-current-row
              >
                <el-table-column type="selection" width="45" align="center" />
                <el-table-column
                  label="企业名称"
                  align="center"
                  prop="enterpriseName"
                />
                <el-table-column
                  label="联系人"
                  align="center"
                  prop="contacts"
                />
                <el-table-column
                  label="联系电话"
                  align="center"
                  prop="telephone"
                  show-overflow-tooltip="true"
                />
              </el-table>
              <pagination
                v-show="total1 > 0"
                :total="total1"
                :page.sync="queryEnterpriseParams.pageNum"
                :limit.sync="queryEnterpriseParams.pageSize"
                @pagination="getEnterpriseList"
              />
            </el-col>
          </el-tab-pane>
          <el-tab-pane label="公海" name="two">
            <el-row>
              <el-col :span="24">
                <el-form
                  :model="querySeasParams"
                  ref="queryFormSeas"
                  size="small"
                  :inline="true"
                  v-show="showSearch"
                  label-width="100px"
                >
                  <el-form-item label="企业名称" prop="enterpriseName">
                    <el-input
                      v-model="querySeasParams.enterpriseName"
                      placeholder="请输入企业名称"
                      clearable
                      @keyup.enter.native="handleQuerySeas"
                    />
                  </el-form-item>
                  <el-form-item>
                    <el-button
                      type="primary"
                      icon="el-icon-search"
                      size="mini"
                      @click="handleQuerySeas"
                      >搜索</el-button
                    >
                    <el-button
                      icon="el-icon-refresh"
                      size="mini"
                      @click="resetQuerySeas"
                      >重置</el-button
                    >
                    <el-button
                      type="primary"
                      size="mini"
                      @click="saveSelectSeas"
                      >确定</el-button
                    >
                  </el-form-item>
                </el-form>

                <el-table
                  ref="tableSeas"
                  v-loading="loading"
                  :data="seasList"
                  @selection-change="handleSelectionChangeSeas"
                >
                  <el-table-column type="selection" width="45" align="center" />
                  <el-table-column
                    label="企业名称"
                    align="center"
                    prop="enterpriseName"
                  />
                  <el-table-column
                    label="联系人"
                    align="center"
                    prop="contacts"
                  />
                  <el-table-column
                    label="联系电话"
                    align="center"
                    prop="telephone"
                  />
                </el-table>
                <pagination
                  v-show="total4 > 0"
                  :total="total4"
                  :page.sync="querySeasParams.pageNum"
                  :limit.sync="querySeasParams.pageSize"
                  @pagination="getSeasList"
                />
              </el-col>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="线索" name="three">
            <el-row>
              <el-col :span="24">
                <el-form
                  :model="queryEleParams"
                  ref="queryFormEle"
                  size="small"
                  :inline="true"
                  v-show="showSearch"
                  label-width="100px"
                >
                  <el-form-item label="企业名称" prop="enterpriseName">
                    <el-input
                      v-model="queryEleParams.enterpriseName"
                      placeholder="请输入企业名称"
                      clearable
                      @keyup.enter.native="handleQueryEle"
                    />
                  </el-form-item>
                  <el-form-item>
                    <el-button
                      type="primary"
                      icon="el-icon-search"
                      size="mini"
                      @click="handleQueryEle"
                    >搜索</el-button
                    >
                    <el-button
                      icon="el-icon-refresh"
                      size="mini"
                      @click="resetQueryEle"
                    >重置</el-button
                    >
                    <el-button
                      type="primary"
                      size="mini"
                      @click="saveSelectEle"
                    >确定</el-button
                    >
                  </el-form-item>
                </el-form>

                <el-table
                  ref="tableEle"
                  v-loading="loading"
                  :data="eleList"
                  @selection-change="handleSelectionChangeEle"
                >
                  <el-table-column type="selection" width="45" align="center" />
                  <el-table-column
                    label="企业名称"
                    align="center"
                    prop="enterpriseName"
                  />
                  <el-table-column
                    label="联系人"
                    align="center"
                    prop="contacts"
                  />
                  <el-table-column
                    label="联系电话"
                    align="center"
                    prop="telephone"
                  />
                </el-table>
                <pagination
                  v-show="total5 > 0"
                  :total="total5"
                  :page.sync="queryEleParams.pageNum"
                  :limit.sync="queryEleParams.pageSize"
                  @pagination="getEleList"
                />
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-row>
    </el-dialog>
    <el-dialog
      :title="titleProduct"
      :visible.sync="openProduct"
      width="1200px"
      append-to-body
    >
      <el-row>
        <el-col>
          <el-form
            :model="queryContractProductParams"
            ref="queryContractForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="68px"
          >
            <el-form-item label="产品类别" prop="productType">
              <el-select
                v-model="queryContractProductParams.productType"
                placeholder="请选择产品类别"
                clearable
              >
                <el-option
                  v-for="dict in dict.type.product_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="产品编号" prop="productNo">
              <el-input
                v-model="queryContractProductParams.productNo"
                placeholder="请输入产品编号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="产品名称" prop="productName">
              <el-input
                v-model="queryContractProductParams.productName"
                placeholder="请输入产品名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="handleQueryProduct"
                >搜索</el-button
              >
              <el-button
                icon="el-icon-refresh"
                size="mini"
                @click="resetQueryProduct"
                >重置</el-button
              >
              <el-button type="primary" size="mini" @click="saveContractProduct"
                >确定</el-button
              >
            </el-form-item>
          </el-form>
          <el-table
            v-loading="loading"
            :data="qualificationList"
            ref="tableProduct"
            @selection-change="handleSelectionChangeContractProduct"
            row-key="id"
          >
            <el-table-column
              type="selection"
              width="45"
              align="center"
              :reserve-selection="true"
            />
            <el-table-column label="序号" type="index" :index="indexMethod" />
            <el-table-column label="产品类别" align="center" prop="productType">
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.product_type"
                  :value="scope.row.productType"
                />
              </template>
            </el-table-column>
            <el-table-column label="产品编号" align="center" prop="productNo" />
            <el-table-column label="产品名称" align="center" prop="productName"/>
            <el-table-column label="产品规格" align="center" prop="productSpecs" />
          </el-table>
          <pagination
            v-show="total2 > 0"
            :total="total2"
            :page.sync="queryContractProductParams.pageNum"
            :limit.sync="queryContractProductParams.pageSize"
            @pagination="getProductList"
          />
        </el-col>
      </el-row>
    </el-dialog>
    <el-dialog
      title="填写费用"
      :visible.sync="addFeesOpen"
      width="400px"
      append-to-body
    >
      <el-form
        ref="formFees"
        :model="formFees"
        :inline="true"
        :rules="rulesFees"
      >
        <el-form-item label="费用" prop="pricingRange" label-width="80px">
          <el-input v-model="formFees.pricingRange" placeholder="请输入费用" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFessForm">确 定</el-button>
        <el-button @click="cancelFees">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getContractInfo,
  saveContractPayment,
  updateContractPayment
} from "@/api/contract/info";
import {
  listMethod
} from "@/api/contract/method";
import { listPerson } from "@/api/enterprise/person";
import { listInfo, getInfo } from "@/api/enterprise/info";
import {
  listReviewInfo,
  addReviewInfo
} from "@/api/contract/reviewInfo";
import { listQualificationAll } from "@/api/qualificationInfo/qualification";
import {
  listProductInfo,
  getProductInfo,
  delProductInfo,
  addProductInfo,
  updateProductInfo,
  updateContractRemark
} from "@/api/contract/productInfo";
import { listElectric, returnEle, updateClass, editBusinessManager, convert, treeElectric,listAllPerson } from "@/api/electric/electric";
import { listReceivable } from "@/api/project/receivable";
import FileView from "@/components/FileView/index";
import { listSeas, getSeas } from "@/api/highSeas/seas";
import SelectUser from "../system/role/selectUser.vue";
import { listType } from "@/api/maintype/type";
import Treeselect from "@riophae/vue-treeselect";
import MainType from "@/components/MainType/index";
import EnterpriseInfo from "../enterprise/info/index.vue";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {listQualification} from "../../api/qualificationInfo/qualification";
export default {
  name: "Information",
  dicts: [
    "business_classify",
    "customer_industry",
    "business_state",
    "tracking_stage",
    "enterprise_records",
    "product_type",
    "product_status",
    "customer_industry",
    "administrative_area",
    "qualification_resume_status",
    "contract_review_result",
  ],
  components: { Treeselect, SelectUser, FileView, EnterpriseInfo, MainType },
  props: {
    opt: {
      type: String,
      default: "",
    },
    seas: {
      type: String,
      default: "0",
    },
    id: {
      type: String,
      default: "",
    },
    obj: {
      type: Object,
      default: null,
    },
    //序号
    index: {
      type: Number,
      default: 0,
    },
    uuid: {
      type: String,
      default: "",
    },
    isClick: {
      type: Boolean,
      default: "",
    },
    classId: {
      type: String,
      default: "",
    },
    business: {
      type: Object,
      default: null,
    },
    cId: {
      type: String,
      default: "",
    },
    reContractId: {
      type: String,
      default: "",
    },
    reContractName: {
      type: String,
      default: "",
    },
    customerId: {
      type: String,
      default: "",
    },
    convenant: {
      type: String,
      default: "",
    },
    businessoididId: {
      type: String,
      default: null
    },
    enterpriseId: {
      type: String,
      default: null
    },
    enterpriseName: {
      type: String,
      default: null
    },
    grandsonClass:{
      type:String,
      default:null
    }
  },
  data() {
    var salespersonName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("销售人员不能为空"));
      }
      return callback();
    };
    var enterpriseName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("客户名称不能为空"));
      }
      return callback();
    };
    var reviewer = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("评审人不能为空"));
      }
      return callback();
    };
    return {
      seasList:[],
      eleList:[],
      activeNewName: "one",
      isBtn: true,
      addFeesOpen: false,
      isSave: true,
      showRelated: false,
      isView: false,
      readonly: true,
      disabled: false,
      openProduct: false,
      isDel: true,
      isTree: false,
      enterpriseCode: "enterprise",
      contractCode: "contractInfo",
      qualificationCode: "qualification",
      titleProduct: "产品选择",
      isSwitch: true,
      isReview: true,
      editableRowIndex:null,
      isOpen: false,
      bId: "",
      refreshKey: 0,
      //选显卡默认选中
      activeName: "first",
      userType: "1",
      sign: "1",
      // 遮罩层
      loading: true,
      // 选中数组
      eIds: [],
      eName: [],
      productIds: [],
      reviewList: [],
      productNames: [],
      productTypes: [],
      productCodes: [],
      productRanges: [],
      quantitys: [],
      productSpecsArr: [],
      eCustomerAddress: [],
      eCustomerContact: [],
      eTelephone: [],
      productInfoList: [],
      qualificationList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1: 0,
      total2: 0,
      total3: 0,
      total4: 0,
      total5: 0,
      sName: [],
      sIds: [],
      eleIds:[],//线索客户id
      eNames:[],//线索客户名称
      eContacts:[],//联系人
      sTeles: [],
      elePhone:[],//联系电话
      sContacts: [],
      // 【请填写功能名称】表格数据
      infoList: [],
      tableData: [],
      personName: [],
      personPhone: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      fileType: 0,
      // 表单参数
      queryContractForm: {},
      productForm: {},
      reviewerName: "",
      formReview: {},
      form: {
        creationTime: this.showDate(),
        creationName: this.$store.state.user.name,
      },
      rulesFees: {
        pricingRange: [
          { required: true, message: "费用不能为空", trigger: "change" },
          {
            pattern: /^[1-9]\d*$/,
            message: "请输入正确的费用",
            trigger: "blur",
          },
        ],
      },
      // 表单校验
      rules: {
        enterpriseName: [
          { required: true, validator: enterpriseName, trigger: "change" },
        ],
        contractName: [
          { required: true, message: "合同名称不能为空", trigger: "blur" },
          { max: 50, message: "合同名称长度不能超过50", trigger: "blur" },
        ],
        contractNumber: [
          { required: true, message: "合同编号不能为空", trigger: "blur" },
          { max: 50, message: "合同编号长度不能超过50", trigger: "blur" },
        ],
        contractAmount: [
          { required: true, message: "合同金额不能为空", trigger: "change" },
          {
            pattern: /^[1-9]\d*$/,
            message: "请输入正确的合同金额",
            trigger: "blur",
          },
        ],
        customerContact: [
          { required: true, message: "客户联系人不能为空", trigger: "blur" },
          { max: 50, message: "客户联系人长度不能超过50", trigger: "blur" },
        ],
        telephone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" },
          { max: 20, message: "联系电话长度不能超过20", trigger: "blur" },
        ],
        signingTime: [
          { required: true, message: "签订时间不能为空", trigger: "change" },
        ],
        endTime: [
          { required: true, message: "结束时间不能为空", trigger: "blur" },
        ],
        contacts: [
          { required: true, message: "联系人姓名不能为空", trigger: "blur" },
          { max: 36, message: "联系人姓名长度不能超过36", trigger: "blur" },
        ],
        salespersonName: [
          { required: true, validator: salespersonName, trigger: "change" },
        ],
        provideSources: [
          { max: 50, message: "提供来源长度不能超过50", trigger: "blur" },
        ],
        provider: [
          { max: 50, message: "提供人长度不能超过50", trigger: "blur" },
        ],
        cost: [
          {
            pattern: /^[1-9]\d*$/,
            message: "请输入正确的业务费",
            trigger: "blur",
          },
        ],
      },
      reviewRules: {
        reviewer: [{ required: true, validator: reviewer, trigger: "change" }],
      },
      formFees: {
        businessId:null
      },
      businessId: null,
      optionData: null,
      querySeasParams: {
        pageNum: 1,
        pageSize: 5,
        enterpriseName: null,
        administrativeArea: null,
        enterpriseNature: null,
        industry: null,
        classificationId: null,
      },
      queryEleParams: {
        pageNum: 1,
        pageSize: 5,
        enterpriseName: null,
        administrativeArea: null,
        enterpriseNature: null,
        industry: null,
        classificationId: null,
      },
      queryReceivableParams: {
        pageNum: 1,
        pageSize: 15,
        contractId: null,
        status: null,
      },
      queryPersonParams: {
        pageNum: 1,
        pageSize: 15,
        enterpriseId: null,
        enterpriseName:null,
        organizationId: null,
      },
      queryReviewParams: {
        pageNum: 1,
        pageSize: 15,
        reviewId: null,
        contractId: null,
        reviewerId: null,
        reviewer: null,
        reviewComments: null,
        reviewTime: null,
        reviewResult: null,
      },
      queryContractProductParams: {
        pageNum: 1,
        pageSize: 15,
        approve: null,
        productStatus: null,
        productType: null,
        productNo: null,
        productName: null,
        classificationId: null,
      },
      queryProductParams: {
        pageNum: 1,
        pageSize: 15,
        contractId: null,
        productId: null,
        productCategory: null,
        productNumber: null,
        productName: null,
        pricingRange: null,
      },
      queryPaymentParams: {
        pageNum: 1,
        pageSize: 15,
        paymentId: null,
        contractId: null,
        paymentName: null,
        amountCollected: null,
        estimatedCollectionTime: null,
      },
      queryEnterpriseParams: {
        pageNum: 1,
        pageSize: 5,
        enterpriseName: null,
        enterpriseSource: null,
        enterpriseAbbreviation: null,
        administrativeArea: null,
        legalRepresentative: null,
        establishmentDate: null,
        contractAmount: null,
        enterpriseLabel: null,
        registeredCapital: null,
        industry: null,
        contacts: null,
        telephone: null,
        bankName: null,
        taxId: null,
        developmentId: null,
        transactionId: null,
        developmentManager: null,
        businessManager: null,
        enterpriseAddress: null,
        businessScope: null,
        enterpriseNature: null,
        markAs: "1",
        belongTo: null,
        creationTime: null,
        operateTime: null,
        operateId: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        classificationId: null,
      },
    };
  },
  created() {
    this.listType();
    this.selectPerson();
    if (this.opt == "add") {
      this.fileType = 0;
      this.businessId = this.uuid;
      this.isSwitch = this.isClick;
      this.form.enterpriseId = this.enterpriseId;
      this.form.enterpriseName = this.enterpriseName;
    }
    if (this.opt == "edit") {
      this.fileType = 1;
      this.isReview = true;
      this.businessId = this.id;
      this.bId = this.id;
      this.isSwitch = this.isClick;
      this.handleUpdate(this.id);
    }
    if (this.opt == "view") {
      this.isBtn = false;
      this.businessId = this.id;
      this.fileType = 2;
      this.isView = true;
      this.isReview = false;
      this.isSave = false;
      this.bId = this.id;
      this.isSwitch = false;
      this.handleUpdate(this.id);
    }
    if (this.opt == "change") {
      this.businessId = this.uuid;
      this.fileType = 0;
      this.showRelated = true;
      this.isSwitch = this.isClick;
      this.form.relatedContractId = this.reContractId;
      this.form.relatedContractName = this.reContractName;
    }
    if (this.opt == "addContract") {
      this.fileType = 0;
      this.isReview = true;
      this.bId = this.uuid;
      this.businessId = this.bId;
      this.cId = this.bId;
      this.isSwitch = this.isClick;
      this.handleUpdateContract(this.customerId);
    }
    this.getContractProductList();
    this.getProductList();
    this.getEnterpriseList();
    this.getEleList();
    this.getReviewList();
    this.getSeasList();
  },
  methods: {
    // 通用防抖函数：delay毫秒内只执行一次
    debounce(func, delay = 500) {
      let timer = null;
      return function(...args) {
        clearTimeout(timer);
        timer = setTimeout(() => {
          func.apply(this, args);
        }, delay);
      };
    },
    //备注
    handleRemarkBlur: function() {
      return this.debounce(async (row) => {
        // 原逻辑保持不变
        await updateContractRemark(row);
        this.$message.success("备注保存成功");
      });
    },
    //数量
    handleQuantityBlur(row){
      return this.debounce(async (row) => {
        // 原逻辑保持不变
        const quantity = Number(row.quantity);
        if (isNaN(quantity) || quantity < 0) {
          this.$message.error('请输入有效的数量');
          return;
        }
        await updateContractRemark(row);
        this.$message.success("数量保存成功");
      });
    },
    //合同交期
    handleContractDueDateBlur(row){
      return this.debounce(async (row) => {
        // 原逻辑保持不变
        await updateContractRemark(row);
        this.$message.success("合同交期保存成功");
      });
    },
    getSeasList() {
      this.loading = true;
      listSeas(this.querySeasParams).then(response => {
        this.seasList = response.rows;
        this.total4 = response.total;
        this.loading = false;
      });
    },
    getEleList() {
      this.loading = true;
      listElectric(this.queryEleParams).then(response => {
        this.eleList = response.rows;
        this.total5 = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuerySeas() {
      this.querySeasParams.pageNum = 1;
      this.getSeasList();
    },
    /** 重置按钮操作 */
    resetQuerySeas() {
      this.resetForm("queryFormSeas");
      this.handleQuerySeas();
    },
    /** 搜索按钮操作 */
    handleQueryEle() {
      this.queryEleParams.pageNum = 1;
      this.getEleList();
    },
    /** 重置按钮操作 */
    resetQueryEle() {
      this.resetForm("queryFormEle");
      this.handleQueryEle();
    },
    dateOptions(time) {
      return time.getTime() < Date.now() - 24 * 60 * 60 * 1000;
    },
    cancelFees() {
      this.addFeesOpen = false;
    },
    resetFees() {
      this.formFees = {
        id: null,
        contractId: null,
        productId: null,
        productCategory: null,
        productNumber: null,
        productName: null,
        pricingRange: null,
      };
      this.resetForm("formFees");
    },
    submitFessForm() {
      // this.formFees.businessId=this.businessoididId
      console.log(this.businessId,'this.businessId');
      this.$refs["formFees"].validate(valid => {
        if (valid) {
          updateProductInfo(this.formFees).then(response => {
            this.$modal.msgSuccess("填写成功");
            this.addFeesOpen = false;
            this.getContractProductList();
          });
        }
      });
    },
    handleUpdateContract(id) {
      this.reset();
      this.form.contractName = this.convenant;
      getInfo(id).then(response => {
        if (
          response.data.enterpriseId == "" ||
          response.data.enterpriseId == null
        ) {
          getSeas(id).then(response => {
            this.form.enterpriseId = response.data.enterpriseId;
            this.form.enterpriseName = response.data.enterpriseName;
            this.form.customerAddress = response.data.enterpriseAddress;
            this.form.customerContact = response.data.contacts;
            this.form.telephone = response.data.telephone;
            this.form.creationTime = this.showDate();
            this.form.creationName = this.$store.state.user.name;
          });
        } else {
          this.form.enterpriseId = response.data.enterpriseId;
          this.form.enterpriseName = response.data.enterpriseName;
          this.form.customerAddress = response.data.enterpriseAddress;
          this.form.customerContact = response.data.contacts;
          this.form.telephone = response.data.telephone;
          this.form.creationTime = this.showDate();
          this.form.creationName = this.$store.state.user.name;
        }
      });
    },
    getRowKeys(row) {
      return row.id;
    },
    submitReviewForm() {
      this.$refs["formReview"].validate(valid => {
        if (valid) {
          const reviewInfo = {
            reviewId: this.guid(),
            contractId: this.cId,
            reviewerId: this.formReview.reviewerId,
            reviewer: this.formReview.reviewer,
          };
          addReviewInfo(reviewInfo).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getReviewList();
          });
        }
      });
    },
    selectReviewUser() {
      this.userShow(2);
    },
    getReviewList() {
      this.loading = true;
      this.queryReviewParams.contractId = this.cId;
      listReviewInfo(this.queryReviewParams).then(response => {
        this.reviewList = response.rows;
        this.loading = false;
      });
    },
    saveContractProduct() {
      if (
        this.productIds.toString() == "" ||
        this.productIds.toString() == null
      ) {
        this.$modal.msgError("请先选择产品！");
      } else {
        const productInfo = {
          contractId: this.cId,
          productId: this.productIds.toString(),
          productCategory: this.productTypes.toString(),
          productNumber: this.productCodes.toString(),
          productName: this.productNames.toString(),
          quantity: this.quantitys.toString(),
          productSpecs: this.productSpecsArr.toString()
        };
        addProductInfo(productInfo).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.openProduct = false;
          this.isReview = false;
          this.getContractProductList();
        });
      }
    },
    resetQueryProduct() {
      this.queryContractProductParams.classificationId = null;
      this.queryContractProductParams.productStatus = null;
      this.resetProduct();
      this.handleQueryProduct();
    },
    handleQueryProduct() {
      this.queryContractProductParams.pageNum = 1;
      this.getProductList();
    },
    selectProduct() {
      // var numbers = this.productInfoList;
      // setTimeout(() => {
      //   this.carCheck(numbers);
      // }, 500);
      this.openProduct = true;
      this.$refs.tableProduct.clearSelection();
      console.log(this.$refs.tableProduct);
    },
    carCheck(numbers) {
      this.qualificationList.forEach(item => {
        for (var j = 0; j < numbers.length; j++) {
          if (item.id == numbers[j].productId) {
            this.$refs.tableProduct.toggleRowSelection(item, true);
          }
        }
      });
    },
    handleSelectionChangeContractProduct(selection) {
      this.productIds = selection.map(item => item.id);
      this.productNames = selection.map(item => item.productName);
      this.productCodes = selection.map(item => item.productNo);
      this.productTypes = selection.map(item => item.productType);
      this.productRanges = selection.map(item => item.productRange);
      this.productSpecsArr = selection.map(item => item.productSpecs);
      this.quantitys = selection.map(item => item.quantity);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      console.log("选择行产品信息"+JSON.stringify(selection));
    },
    getProductList() {
      this.loading = true;
      this.queryContractProductParams.productStatus = "已上架";
      listQualification(this.queryContractProductParams).then(response => {
        this.qualificationList = response.rows;
        var numbers = this.productInfoList;
        setTimeout(() => {
          this.carCheck(numbers);
        }, 300);
        this.total2 = response.total;
        this.loading = false;
      });
    },
    getNodeProduct(data, node, obj) {
      if (data.id == "650c44e1-b575-4b62-9d54-1ba9d1e8abb7") {
        this.resetQueryProduct();
      } else {
        this.getProductList();
      }
    },
    cancelProduct() {
      this.$emit("change");
    },
    getContractProductList() {
      this.loading = true;
      this.queryProductParams.contractId = this.cId;
      listProductInfo(this.queryProductParams).then(response => {
        this.productInfoList = response.rows;
        if (this.productInfoList.length != 0) {
          this.isReview = false;
        }
        this.total3 = response.total;
        this.loading = false;
      });
    },
    addContractInfo() {
      var tableList = this.tableData;
      var num = 0;
      for (var i = 0; i < tableList.length; i++) {
        if (
          tableList[i].paymentName == "" ||
          tableList[i].paymentName == null ||
          tableList[i].amountCollected == "" ||
          tableList[i].amountCollected == null ||
          tableList[i].estimatedCollectionTime == "" ||
          tableList[i].estimatedCollectionTime == null
        ) {
          num++;
        }
      }
      if (num > 0) {
        this.$message.error("请先填写好收款方式！");
      } else {
        this.tableData.push({
          indexTwo: tableList.length + 1,
          paymentId: this.guid(),
          contractId: this.uuid,
          paymentName: "",
          amountCollected: "",
          estimatedCollectionTime: "",
        });
      }
    },
    delContractListInfo(row) {
      this.tableData = this.tableData.filter(
        data => data.paymentId !== row.paymentId
      );
    },
    guid() {
      function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
      }
      return (
        S4() +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        S4() +
        S4()
      );
    },
    /** 搜索按钮操作 */
    handleQueryEnterprise() {
      this.queryEnterpriseParams.pageNum = 1;
      this.getEnterpriseList();
    },
    /** 重置按钮操作 */
    resetQueryEnterprise() {
      this.resetForm("queryFormEnterprise");
      this.handleQueryEnterprise();
    },

    getEnterpriseList() {
      this.loading = true;
      listInfo(this.queryEnterpriseParams).then(response => {
        this.infoList = response.rows;
        this.total1 = response.total;
        this.loading = false;
      });
    },
    getFile(data) {
      console.log(JSON.stringify(data));
    },
    indexMethod(index) {
      return (
        (this.queryContractProductParams.pageNum - 1) *
          this.queryContractProductParams.pageSize +
        index +
        1
      );
    },
    listType() {
      listType({ typeCode: "contractInfo" }).then(res => {
        this.optionData = res.data;
      });
    },

    handleClick(tab, event) {
      if (tab.name == "first") {
      }
      if (tab.name == "second") {
      }
      if (tab.name == "third") {
      }
    },
    userShow(type) {
      this.show = type;
      this.$refs.select.show();
    },
    handleDeleteProduct(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除产品名称为"' + row.productName + '"的数据信息？')
        .then(function () {
          return delProductInfo(ids);
        })
        .then(() => {
          this.getContractProductList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    addFees(row) {
      this.resetFees();
      const id = row.id;
      getProductInfo(id).then(response => {
        this.formFees = response.data;
      });
      this.addFeesOpen = true;
    },
    // 取消按钮
    cancel() {
      this.$emit("change");
    },
    // 表单重置
    resetProduct() {
      this.queryContractForm = {
        id: null,
        productType: null,
        productNo: null,
        productName: null,
        productPrice: null,
        productSellPrice: null,
        productStatus: null,
        enterpriseId: null,
        enters: null,
        productRemark: null,
        exeStandard: null,
        template: null,
        operateId: null,
        departmentId: null,
        organizationId: null,
        departmentName: null,
        organizationName: null,
        creationTime: null,
        operateTime: null,
        createId: null,
        selectUrl: null,
        userName: null,
        releaseTime: null,
        approve: null,
        classificationId: null,
        uploadFile: null,
      };
      this.resetForm("queryContractForm");
    },
    reset() {
      this.form = {
        contractId: null,
        classificationId: null,
        contractName: null,
        contractNumber: null,
        relatedContractId: null,
        relatedContractName: null,
        contractAmount: null,
        signingTime: null,
        endTime: null,
        enterpriseId: null,
        enterpriseName: null,
        customerAddress: null,
        customerContact: null,
        telephone: null,
        salespersonId: null,
        salespersonName: null,
        additionalTerms: null,
        belongTo: null,
        provideSources: null,
        provider: null,
        cost: null,
        creationId: null,
        creationName: null,
        creationTime: null,
        operateTime: null,
        operateId: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        delFlag: null,
        amountReceived: null,
        state: null,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {

      var amount = /^[1-9]\d*$/;
      var sumAmount = 0;
      this.$refs["form"].validate(valid => {
        if (valid) {
          var tableList = this.tableData;
          if (tableList.length == 0) {
            this.$message.error("请填写收款方式信息！");
            return;
          }
          for (var i = 0; i < tableList.length; i++) {
            if (
              tableList[i].paymentName == "" ||
              tableList[i].paymentName == null ||
              tableList[i].amountCollected == "" ||
              tableList[i].amountCollected == null ||
              tableList[i].estimatedCollectionTime == "" ||
              tableList[i].estimatedCollectionTime == null
            ) {
              this.$message.error("请填写收款方式信息！");
              return;
            }
            if (!amount.test(tableList[i].amountCollected)) {
              this.$message.error("请输入正确的收款金额！");
              return;
            }
            sumAmount = sumAmount + parseInt(tableList[i].amountCollected);
          }
          if (sumAmount != this.form.contractAmount) {
            this.$message.error("收款总金额应等于合同金额！");
            return;
          }
          if (
            new Date(this.form.endTime).getTime() <
            new Date(this.form.signingTime).getTime()
          ) {
            this.$message.error("合同签订时间不能大于合同结束时间！");
            return;
          }
          if (this.productInfoList.length == 0) {
            this.$message.error("请选择产品信息！");
            return;
          }
          this.$refs["form"].validate(valid => {
            if (this.form.contractId != null) {
              this.form.businessId=this.businessoididId
              //  console.log(this.businessId,'this.businessId');
              this.form["contractPaymentMethods"] = this.tableData;
              const data = this.form;
              updateContractPayment(data).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.$emit("change");
                this.open = false;
              });
            } else {
              this.form.contractId = this.uuid;
              this.form.businessId=this.businessoididId
              // console.log(this.businessId,'this.businessId');
              this.form["contractPaymentMethods"] = this.tableData;
              const data = this.form;
              saveContractPayment(data).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.isSwitch = false;
                this.open = false;
                this.$emit("change");
              });
            }
          });
        }
      });
    },
    /** 修改按钮操作 */
    handleUpdate(id) {
      this.reset();
      getContractInfo(id).then(response => {
        this.form = response.data;
        if (
          this.form.relatedContractName != "" &&
          this.form.relatedContractName != null
        ) {
          this.showRelated = true;
        }
        this.form.creationTime = this.formatterDate(this.form.creationTime);
      });
      this.queryPaymentParams.contractId = id;
      listMethod(this.queryPaymentParams).then(response => {
        this.tableData = response.rows;
      });
      this.queryReceivableParams.contractId = id;
      this.queryReceivableParams.status = "1";
      listReceivable(this.queryReceivableParams).then(response => {
        var listTable = response.rows;
        var sum = 0;
        for (var a = 0; a < listTable.length; a++) {
          sum = sum + parseInt(listTable[a].paidInAmount);
        }
        this.form.amountReceived = sum;
      });
    },
    //根据企业和组织机构id查询客户人员信息
    selectPerson() {
      this.queryPersonParams.enterpriseId = this.enterpriseId;
      this.queryPersonParams.enterpriseName=this.enterpriseName;
      this.queryPersonParams.organizationId = this.$store.state.user.info.orgId;
      listPerson(this.queryPersonParams).then(response => {
        this.personName = response.rows;
        this.personPhone = response.rows;
      });
    },
    showDate() {
      var mydate = new Date();
      var str = "" + mydate.getFullYear() + "-";
      str +=
        mydate.getMonth() + 1 <= 9
          ? "0" + (mydate.getMonth() + 1) + "-"
          : mydate.getMonth() + 1 + "-";
      str += mydate.getDate() <= 9 ? "0" + mydate.getDate() : mydate.getDate();
      return str;
    },
    formatterDate(date) {
      var mydate = new Date(date);
      var str = "" + mydate.getFullYear() + "-";
      str +=
        mydate.getMonth() + 1 <= 9
          ? "0" + (mydate.getMonth() + 1) + "-"
          : mydate.getMonth() + 1 + "-";
      str += mydate.getDate() <= 9 ? "0" + mydate.getDate() : mydate.getDate();
      return str;
    },
    close() {
      this.open = false;
    },
    enterprise() {
      this.open = true;
    },
    selectUser(userId, userName, phone, position) {
      if (this.show == "1") {
        this.$set(this.form, "salespersonName", userName);
        this.$set(this.form, "salespersonId", userId);
      }
      if (this.show == "2") {
        this.$set(this.formReview, "reviewer", userName);
        this.$set(this.formReview, "reviewerId", userId);
      }
    },
    handleSelectionChangeEnterprise(selection) {
      if (selection.length > 1) {
        this.$refs.tableEnterprise.clearSelection(); // 清空所有选择
        this.$refs.tableEnterprise.toggleRowSelection(selection.pop()); // 设置选择项
      } else {
        this.eIds = selection.map(item => item.enterpriseId);
        this.eName = selection.map(item => item.enterpriseName);
        this.eCustomerAddress = selection.map(item => item.enterpriseAddress);
        this.eCustomerContact = selection.map(item => item.contacts);
        this.eTelephone = selection.map(item => item.telephone);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      }
    },
    handleSelectionChangeSeas(selection) {
      if (selection.length > 1) {
        this.$refs.tableSeas.clearSelection(); // 清空所有选择
        this.$refs.tableSeas.toggleRowSelection(selection.pop()); // 设置选择项
      } else {
        this.sIds = selection.map(item => item.enterpriseId);
        this.sName = selection.map(item => item.enterpriseName);
        this.sContacts = selection.map(item => item.contacts);
        this.eCustomerAddress = selection.map(item => item.enterpriseAddress);
        this.sTeles = selection.map(item => item.telephone);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      }
    },
    handleSelectionChangeEle(selection){
      console.log(selection)
      if (selection.length > 1) {
        this.$refs.tableEle.clearSelection(); // 清空所有选择
        this.$refs.tableEle.toggleRowSelection(selection.pop()); // 设置选择项
      } else {
        this.eleIds = selection.map(item => item.electricId);
        this.eNames = selection.map(item => item.enterpriseName);
        this.sContacts = selection.map(item => item.contacts);
        this.eCustomerAddress = selection.map(item => item.enterpriseAddress);
        this.elePhone = selection.map(item => item.telephone);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      }
    },

    getNodeEnterprise(data, node, obj) {
      this.getEnterpriseList();
    },
    saveSelectEnterprise() {
      if (this.eIds.toString() == "" || this.eIds.toString() == null) {
        this.$modal.msgError("请先选择客户！");
      } else {
        this.$set(this.form, "enterpriseName", this.eName.toString());
        this.$set(this.form, "enterpriseId", this.eIds.toString());
        this.$set(
          this.form,
          "customerAddress",
          this.eCustomerAddress.toString()
        );
        this.queryPersonParams.enterpriseId = this.eIds.toString();
        this.queryPersonParams.organizationId =
          this.$store.state.user.info.orgId;
        listPerson(this.queryPersonParams).then(response => {
          this.personName = response.rows;
          this.personPhone = response.rows;
        });
        this.$set(
          this.form,
          "customerContact",
          this.eCustomerContact.toString()
        );
        this.$set(this.form, "telephone", this.eTelephone.toString());
        this.close();
      }
    },
    saveSelectSeas() {
      if (this.sIds.toString() == "" || this.sIds.toString() == null) {
        this.$modal.msgError("请先选择客户！");
      } else {
        this.$set(this.form, "enterpriseName", this.sName.toString());
        this.$set(this.form, "enterpriseId", this.sIds.toString());
        this.$set(
          this.form,
          "customerAddress",
          this.eCustomerAddress.toString()
        );
        this.queryPersonParams.enterpriseId = this.sIds.toString();
        this.queryPersonParams.organizationId =
          this.$store.state.user.info.orgId;
        listPerson(this.queryPersonParams).then(response => {
          this.personName = response.rows;
          this.personPhone = response.rows;
        });
        this.$set(this.form, "customerContact", this.sContacts.toString());
        this.$set(this.form, "telephone", this.sTeles.toString());
        this.close();
      }
    },
    saveSelectEle(){
      if (this.eleIds.toString() == "" || this.eleIds.toString() == null) {
        this.$modal.msgError("请先选择客户！");
      } else {
        this.$set(this.form, "enterpriseName", this.eNames.toString());
        this.$set(this.form, "enterpriseId", this.eleIds.toString());
        this.$set(
          this.form,
          "customerAddress",
          this.eCustomerAddress.toString()
        );
        this.queryPersonParams.enterpriseId = this.eleIds.toString();
        this.queryPersonParams.organizationId =
          this.$store.state.user.info.orgId;
        listPerson(this.queryPersonParams).then(response => {
          this.personName = response.rows;
          this.personPhone = response.rows;
        });
        this.$set(this.form, "customerContact", this.sContacts.toString());
        this.$set(this.form, "telephone", this.elePhone.toString());
        this.close();
      }
    }
  },
};
</script>

<style scoped lang="scss">
::v-deep .el-table .el-table__header-wrapper .el-checkbox {
  display: none;
}

::v-deep .el-dialog__header {
  padding-top: 5px;
}

.cancel-class {
  color: red;
}

.contract-tabs {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
}

.tab-content-scrollable {
  overflow-y: auto;
  max-height: 70vh;
  padding-right: 10px;
  padding-bottom: 30px;
}
.tab-content-business {
  overflow-y: auto;
  max-height: 50vh;
  padding-right: 10px;
  padding-bottom: 30px;
}

::v-deep .el-tabs__content {
  overflow: visible;
  height: 100%;
}
</style>
